package com.lkd.contract;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.data.domain.PageRequest;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-12-02 14:13
 */
@Data
public class TaskCompleteContract109 {
    private String innerCode; //售货机编码
    private TaskCompleteContractType type;

    public enum TaskCompleteContractType {
        DEPLOY(0) //投放
        ,
        REVOKE(1) //撤机
        ;

        int type;

        TaskCompleteContractType(int type) {
            this.type = type;
        }

        @JsonCreator
        public TaskCompleteContractType getType(int type){
            for(TaskCompleteContractType data : values()){
                if(data.type == type){
                    return data;
                }
            }
            return null;
        }
        @JsonValue //序列化枚举，调用这个方法获取最终值
        public int getType() {
            return type;
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        ObjectMapper objectMapper = new ObjectMapper();
        TaskCompleteContract109 contract109 = new TaskCompleteContract109();
        contract109.setType(TaskCompleteContractType.REVOKE);
        contract109.setInnerCode("1001");
        String s = objectMapper.writeValueAsString(contract109);
        System.out.println(s);
        TaskCompleteContract109 contract1091 = objectMapper.readValue(s, TaskCompleteContract109.class);
        System.out.println(contract1091);

    }
}
